package own.stu.jobgib.playown.alg.leetcode.editor.cn.demo;

import java.util.concurrent.TimeUnit;

public class Truck {
    private Station from;

    private Station to;

    private Integer capacity = 20;

    private volatile Boolean onTheWay = false;

    public Truck(Station from, Station to) {
        this.from = from;
        this.to = to;
    }

    public void loadAndTransport(int num) throws InterruptedException {

        num = Math.min(num, capacity);
        from.takeCar(from.getNums() - num);
        onTheWay = true;
        TimeUnit.SECONDS.sleep(3);
        to.returnCar(to.getNums() + num);
        onTheWay = false;
    }
}
